import pymysql

from APIs.logAPI import LogAPI
from APIs.loginAPI import LoginAPI
from common.config import host


class DoSQL:
    def __init__(self):
        self.db=pymysql.Connection(user='root',
                                   password='123456',
                                   port=3306,
                                   host=host,
                                   database='crm9')

    def doSQL(self,sql):
        a=self.db.cursor()
        b=a.execute(sql)
        print(b)

    def delete_mylog(self):
        a=self.db.cursor()
        b=a.execute("SELECT log_id from 72crm_oa_log where create_user_id =(select user_id FROM 72crm_admin_user where username='admin');")
        c=a.fetchall()
        ll=LoginAPI()
        t=ll.login({'username':'admin','password':'123456'})
        l=LogAPI(t)
        logIds=[]
        for i in c:
            logIds.append(i[0])
        print(logIds)
        for i in logIds:
            d_data={'logId':i}
            l.delete(d_data)



if __name__ == '__main__':
    db=DoSQL()
    # sql='select * from 72crm_admin_user'
    # db.doSQL(sql)
    db.delete_mylog()